package game.model;

import java.awt.Color;

public class Card {
	
	private int value;
	private Color color;
	String imageAddress;
	
	/**
	 * Card constructor.
	 * @param Color c, The Color of the card.
	 * @param int v, the value of the card.
	 */
	public Card(Color c, int v){
		color = c;
		value = v;
		setAddress();
	}
	
	/**
	 * The Color of the Card
	 * @return Color, The Color of the card.
	 */
	public Color getColor(){
		return color;
	}
	
	/**
	 * The Color of the Card
	 * @return int, The value of the card.
	 */
	public int getValue(){
		return value;
	}
	
	/**
	 * The location of the image of the card.
	 * @return String, The location of the image for the card.
	 */
	public String getImageAddress(){
		return imageAddress;
	}
	
	/**
	 * Compare to see if the two cards have the same color.
	 * @return boolean, True if the color of the cards are the same, else false.
	 */
	public boolean compareColor(Card i){
		if((this.getColor()).equals(i.getColor()))
			return true;
		else
			return false;
	}
	
	/**
	 * Compare to see if the two cards have the same value.
	 * @return int, 0 if the color of the cards are the same, 1 if the card has a higher value than the card passed, else -1.
	 */
	public int compareValue(Card i){
		if(this.getValue() == i.getValue())
			return 0;
		else if(this.getValue() > i.getValue())
			return 1;
		else
			return -1;
	}
	
	/**
	 * Check to see if the cards are an exact match.
	 * @return int, 0 if the color of the cards are the same && the value of the cards are the same,
	 *  1 if the value of the card is great than the card passed, else -1.
	 */
	public int compareCard(Card i){
		if(compareValue(i) == 0 && compareColor(i))
			return 0;
		else if(compareColor(i))
			return  compareValue(i);
		else
			return compareValue(i);
	}
	
	/**
	 * Compare that cards match either the value or the color.
	 * @return boolean, true if either the values are the same or the colors are the same, else false.
	 */
	public boolean compareMatch(Card i){
		if(compareValue(i) == 0 || compareColor(i))
			return true;
		else
			return false;
	}
	
	private void setAddress() {
		String address = ".\\images\\";
		
		if(color.equals(Color.BLUE)) {
			address+="blue";
		}
		else if(color.equals(Color.RED)) {
			address+="red";
		}
		else if(color.equals(Color.YELLOW)) {
			address+="yellow";
		}
		else if(color.equals(Color.GREEN)){
			address+="green";
		}
		else if(color.equals(Color.BLACK)) {
			if(value == 0) {
				address+="wildStandard.png";
			}
			else if(value == 1) {
				address+="wildDrawFour.png";
			}
			imageAddress = address;
			return;
		}
		
		if(value == 0) {
			address+="0.png";
		}
		else if(value == 1) {
			address+="1.png";
		}
		else if(value == 2) {
			address+="2.png";
		}
		else if(value == 3) {
			address+="3.png";
		}
		else if(value == 4) {
			address+="4.png";
		}
		else if(value == 5) {
			address+="5.png";
		}
		else if(value == 6) {
			address+="6.png";
		}
		else if(value == 7) {
			address+="7.png";
		}
		else if(value == 8) {
			address+="8.png";
		}
		else if(value == 9) {
			address+="9.png";
		}
		else if(value == 10) {
			address+="Reverse.png";
		}
		else if(value == 11) {
			address+="Skip.png";
		}
		else if(value == 12) {
			address+="DrawTwo.png";
		}
		
		imageAddress = address;
	}
}
